import http from '@/utils/request';
import apis from '@/api/apis';
import { Message} from 'element-ui';
const state = {
    uploadPartInfo:null, 
    uploadLayoutInfo:null,
    lineBroadcas:null,
    syncloading:false
  }
  
  const mutations = {
    SET_UPLOAD_PART_INFO: (state, parts) => {
      // 零件上传任务
      state.uploadPartInfo=parts;
    },
    SET_UPLOAD_LAYOUT_INFO: (state, layouts) => {
      // 排样上传任务
      state.uploadLayoutInfo=layouts;
    },
    CAD_BROADCAST_LINE_UPLOAD: (state, info) => {
      // cad上线后需要提交数据
      state.lineBroadcas=info;
    },
    GET_HANDLE_SYNCHRONOUS: (state, syncs) => {
      // 数据同步
      state.syncloading=syncs;
    },
    SET_SYNC_REFRESH_CODE: (state) => {
      // 数据同步
      state.syncRefreshCode=new Date().getTime();
    }
  }
  
  const actions = { 
    setUploadPartInfo({ commit }, parts) {
      commit('SET_UPLOAD_PART_INFO', parts)
    },
    setUploadLayoutInfo({ commit }, layouts) {
      commit('SET_UPLOAD_LAYOUT_INFO', layouts)
    },
    cadBroadcastLineUpload({ commit }, info) {
      commit('CAD_BROADCAST_LINE_UPLOAD', info)
    },
    async handleSynchronous({ commit }) {
      commit('GET_HANDLE_SYNCHRONOUS', true)
      http
        .get(apis.SYNCHRONOUS)
        .then((res) => {
          commit('GET_HANDLE_SYNCHRONOUS', false)
          commit('SET_SYNC_REFRESH_CODE')
          Message.success('数据已同步');
        })
        .catch((err) => {
          commit('GET_HANDLE_SYNCHRONOUS', false)
        });
    },
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  